/*
* AudioBuilder.h
*
*  Created on: Mar 21, 2013
*      Author: Centny
*/

#ifndef AUDIOBUILDER_H_
#define AUDIOBUILDER_H_

namespace centny {
	namespace abl {
		/*
		block for the audio data.
		*/
		struct AudioBlock {
			int rate;
			float *data;
			int len;
		};
		/*
		free the block.
		*/
		void free(AudioBlock** ab);
		/**
		create audio block.
		*/
		AudioBlock* create(int rate, int bytesPerSample, void* data, int dlen,
			bool derivative = false);
		/**
		convert rate.
		*/
		AudioBlock* convert(AudioBlock* src, int nrate);
		/**
		copy block.
		*/
		AudioBlock* copy(AudioBlock* src);
		/*
		the interface for the block matched handler.
		*/
		class MatchHandler {
			virtual void matched()=0;
			virtual ~MatchHandler() {
			}
		};
		//
		class AudioBuilder {
		protected:
			AudioBlock* taudio;
			int startIdx;
			MatchHandler* mh;
		private:
			//the buffer audio for target rate.
			AudioBlock* baudio;
		public:
			AudioBuilder(AudioBlock* taudio, MatchHandler* mhandler = 0);
			virtual void setTargetRate(int rate);
			virtual void process(AudioBlock* ab);
			virtual ~AudioBuilder();
		};

	}
} /* namespace centny */
#endif /* AUDIOBUILDER_H_ */
